package zhongbo.java.air.flightpath.listener;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;
import zhongbo.java.air.common.enums.SourceType;
import zhongbo.java.air.flightpath.model.entities.FlightPath;
import zhongbo.java.air.flightpath.service.IFlightPathService;

import java.util.Objects;

/**
 * 接收 接引服务的消息
 *
 * @author WeiJin
 * @version 1.0
 * @since 2025/4/3 13:12
 */
@Component
@Slf4j
public class RedisIngestionListener implements MessageListener {

    @Autowired
    private IFlightPathService flightPathService;

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String msg = new String(message.getBody());


        JSONObject parse = JSONUtil.parseObj(msg);
        FlightPath flightPath =parse.toBean(FlightPath.class);
        if (Objects.isNull(flightPath.getSourceType())){
            flightPath.setSourceType("");
        }
        flightPathService.saveFlightPath(flightPath);
    }


}
